<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePrivilegesTable extends Migration
{
    /**
     * Run the migrations.
     * 权限表
     * @return void
     */
    public function up()
    {
        Schema::create('privileges', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('parent_id')->unsigned()->comment('父级ID')->default(0);
            $table->string('name')->comment('权限名称');
            $table->string('method')->comment('请求方式get post update delete');
            $table->string('route')->comment('权限路由');
            $table->char('menu',1)->comment('1 作为菜单显示; 0 不显示')->default(1);
            $table->char('type',1)->comment('权限类型 0:h5页面 1:接口权限')->default(1);
            $table->char('level',1)->comment('权限的限制级别 0:不验证 1:仅需要登录 2.需要赋予权限')->default(2);
            // $table->string('group_name')->comment('权限组名称')->nullable();
            $table->integer('status')->comment('权限状态 1 启用; 0 禁用')->default(1);
            $table->text('description')->comment('权限描述')->nullable();
            $table->string('icon',100)->comment('菜单的图标')->nullable();
            $table->integer('sort')->comment('菜单排序(降序)')->default(0);
            $table->softDeletes();
            $table->timestamps();
            $table->unique(['name','deleted_at']);
        });

        Schema::create('privilege_files', function (Blueprint $table) {
            //字段定义
            $table->increments('id');
            $table->integer('privilege_id')->unsigned()->comment('权限id')->nullable();
            $table->foreign('privilege_id')->on('privileges')->references('id')->onDelete('set null');
            $table->BigInteger('file_id')->unsigned()->comment('图标的文件信息')->nullable();
            $table->foreign('file_id')->on('file_upload')->references('id')->onDelete('set null');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('privileges');
    }
}
